﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Menu : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["CadenaDeConexion"] = ConfigurationManager.ConnectionStrings["SIG"].ConnectionString;
        Session["PerfilInstructorGastronomia"] = ConfigurationManager.AppSettings["PerfilInstructorGastronomia"].ToString();
    }
    protected void LinkButtonAddNew_Click(object sender, EventArgs e)
    {
        ((Calendar)FormViewMenu.FindControl("CalendarFechaMenu")).SelectedDate = DateTime.Now;
        FormViewMenu.Visible = true;
    }
    protected void InsertCancelButton_Click(object sender, EventArgs e)
    {
        LimpiarFormulario();
    }

    private void LimpiarFormularioRecetasDelMenu()
    {
        FormViewRecetasDelMenu.ChangeMode(FormViewMode.ReadOnly);
        FormViewRecetasDelMenu.Visible = false;
    }

    private void LimpiarFormularioTarifas()
    {
        FormViewTarifas.Controls.Clear();
        FormViewTarifas.Visible = false;
    }

    private void LimpiarFormulario()
    {
        LimpiarFormularioRecetasDelMenu();
        LimpiarFormularioTarifas();

        GridViewRecetasDelMenu.Visible = false;
        GridViewTarifas.Visible = false;

        FormViewMenu.Controls.Clear();
        FormViewMenu.Visible = false;
    }

    protected void FormViewMenu_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        LimpiarFormulario();
    }
    protected void FormViewMenu_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["CategoriaMenu"] = ((DropDownList)FormViewMenu.FindControl("DropDownListCategoriaMenu")).SelectedValue;
        e.Values["InstructorGastronomia"] = ((DropDownList)FormViewMenu.FindControl("DropDownListUsuarios")).SelectedValue;
    }

    protected void LinkButtonAddNewTarifa_Click(object sender, EventArgs e)
    {
        FormViewTarifas.Visible = true;
    }
    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        actualizarDetalleDelMenu();
    }
    protected void FormViewTarifas_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["CodigoMenu"] = GridViewMenus.SelectedValue;
        e.Values["PerfilUsuarioTarifa"] = ((DropDownList)FormViewTarifas.FindControl("DropDownListPerfilUsuario")).SelectedValue;
    }
    protected void InsertCancelButton_Click1(object sender, EventArgs e)
    {
        LimpiarFormularioTarifas();
    }
    protected void LinkButtonAddNew_Click1(object sender, EventArgs e)
    {
        FormViewRecetasDelMenu.ChangeMode(FormViewMode.Insert);
        FormViewRecetasDelMenu.Visible = true;
    }
    protected void InsertCancelButton_Click2(object sender, EventArgs e)
    {
        LimpiarFormularioRecetasDelMenu();
    }
    protected void FormViewRecetasDelMenu_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        LimpiarFormularioRecetasDelMenu();
    }
    protected void FormViewRecetasDelMenu_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["Menu"] = GridViewMenus.SelectedValue;
        e.Values["Receta"] = ((DropDownList)FormViewRecetasDelMenu.FindControl("DropDownListRecetas")).SelectedValue;
    }
    protected void GridViewMenus_SelectedIndexChanged(object sender, EventArgs e)
    {
        if (GridViewMenus.SelectedIndex > -1)
        {
            actualizarDetalleDelMenu();
        }
    }

    private void actualizarDetalleDelMenu()
    {
        GridViewTarifas.DataBind();
        GridViewTarifas.Visible = true;
        GridViewRecetasDelMenu.DataBind();
        GridViewRecetasDelMenu.Visible = true;
    }
    protected void InsertCancelButton_Click3(object sender, EventArgs e)
    {
        LimpiarFormularioTarifas();
    }
    protected void FormViewTarifas_ItemInserted(object sender, FormViewInsertedEventArgs e)
    {
        LimpiarFormularioTarifas();
    }
    protected void ObjectDataSourceMenu_Deleted(object sender, ObjectDataSourceStatusEventArgs e)
    {
        Label2.Text = e.OutputParameters["alerta"].ToString();
    }
    protected void DropDownListUsuarios_DataBound(object sender, EventArgs e)
    {
       
    }
    protected void ObjectDataSourceInstructoresPorCedula_Selecting(object sender, ObjectDataSourceSelectingEventArgs e)
    {
        e.InputParameters["numeroDeDocumento"] = ((TextBox)FormViewMenu.FindControl("txtNumeroDeDocumento")).Text;
    }
}
